package com.runen.wnhz.runen.ui.fragment.publicm;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.runen.wnhz.runen.R;
import com.runen.wnhz.runen.data.entity.ShopInfo;
import com.runen.wnhz.runen.di.component.ApplicationComponent;
import com.runen.wnhz.runen.ui.activity.dataservice.DataSerciceDetails;
import com.runen.wnhz.runen.ui.adapter.puadapter.AllRecyclerViewAdapter;
import com.runen.wnhz.runen.ui.fragment.BaseFragment;
import com.runen.wnhz.runen.widget.TitleBuilder;

import java.util.List;

/**
 * Created by Administrator on 2018-04-23.
 * 根据后台传回来的title，增加AllFragment
 */

public class AllFragment extends BaseFragment{

    public static String ID = "type_id";
    public static String SDATE = "sdate";
    public static String EDATE = "edate";
    public static String PAGENUM = "page";
    private String TAG = "AllFragment";
    private String sDate;
    private String eDate;
    private String pageNum;
    private String currentShopTypeId;
    RecyclerView recyclerView;
    private String shopTypeId;
    AllRecyclerViewAdapter adapter;

    //    private List<AllDataEntity> allDatas = new ArrayList<>();
    List<ShopInfo> shopInfoList;

    @Override
    public void setupAcitivtyComponent(ApplicationComponent appComponent) {
      
    }

    public static AllFragment newInstance(String title, String shopTypeId) {
        Bundle args = new Bundle();
        args.putString("title", title);
        args.putString(DataSerciceDetails.SHOPTYPE_ID, shopTypeId);
        AllFragment fragment = new AllFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void init() {
    }

    @Override
    protected int getLayoutView() {
        return R.layout.fragment_all_data;
    }

    @Override
    public void initUiAndListener(View view) {
        recyclerView = view.findViewById(R.id.all_recyclerview);
        initSetData();
    }

    private void initSetData() {
        adapter = new AllRecyclerViewAdapter(getContext(), shopInfoList);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.setAdapter(adapter);

        adapter.setItemClickListener(new AllRecyclerViewAdapter.MyItemClickListener() {
            @Override
            public void onItemClick(View view, ShopInfo data) {
                //跳转带数据服务详情界面
                Log.e(TAG, data.toString());
                Intent intent = new Intent(getContext(), DataSerciceDetails.class);
                //传值shoptypeId,shopId,
                intent.putExtra(DataSerciceDetails.SHOP_ID, data.getShop_id());
                intent.putExtra(DataSerciceDetails.SHOPTYPE_ID, currentShopTypeId);
                intent.putExtra(DataSerciceDetails.SDATE, sDate);
                intent.putExtra(DataSerciceDetails.EDATE, eDate);
                startActivity(intent);
            }
        });
    }

    @Override
    public void initToolBar(TitleBuilder mTitleBuilder) {
        setToolBarVisible(View.GONE);
    }

    @Override
    public void showLoadding() {

    }

    @Override
    public void dimissLoding() {

    }

    @Override
    public void showErrorMessage(String msg) {

    }


    @Override
    public void onTitleButtonClicked(TitleBuilder.TitleButton clicked) {

    }

    //更新数据
    public void update(List<ShopInfo> shopInfoList, String currentShopTypeId, String sDate, String eDate, String pageNum) {
        this.shopInfoList = shopInfoList;
        Log.d("AllFragment:", shopInfoList.toString());
        this.currentShopTypeId = currentShopTypeId;
        this.sDate = sDate;
        this.eDate = eDate;
        this.pageNum = pageNum;
        adapter.update(shopInfoList);
    }
}
